package com.ego.coupon.controller;

import java.util.Arrays;

import com.ego.common.vo.PageVo;
import com.ego.coupon.vo.SeckillSkuRelationSearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ego.coupon.po.SeckillSkuRelation;
import com.ego.coupon.service.SeckillSkuRelationService;
import com.ego.common.util.Result;

import javax.validation.Valid;

/**
 * @program: ego
 * @description 秒杀活动商品关联控制器
 * @author KamTang
 * @date 2022-11-13 13:17:12
 */
@RestController
@RequestMapping("coupon/seckill-sku-relation")
public class SeckillSkuRelationController {

    @Autowired
    private SeckillSkuRelationService seckillSkuRelationService;

    @PostMapping("/search")
    public Result search(@Valid @RequestBody SeckillSkuRelationSearchVo search) {
        PageVo<SeckillSkuRelation> page = seckillSkuRelationService.search(search);
        return Result.ok().put("page", page);
    }

    /**
     * 信息
     */
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Long id){
		SeckillSkuRelation seckillSkuRelation = seckillSkuRelationService.getById(id);
        return Result.ok().put("seckillSkuRelation", seckillSkuRelation);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public Result save(@Valid @RequestBody SeckillSkuRelation seckillSkuRelation){
		seckillSkuRelationService.save(seckillSkuRelation);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public Result update(@Valid @RequestBody SeckillSkuRelation seckillSkuRelation){
		seckillSkuRelationService.updateById(seckillSkuRelation);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public Result delete(@Valid @RequestBody Long[] ids){
		seckillSkuRelationService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
